import java.util.LinkedHashMap;
import java.util.Map;

import commons.UserRating;


public class UserRatingMatrixCache {
	private final static int CACHE_MAX_SIZE = 1000000;
	private LinkedHashMap<Integer, UserRating[]> cache;

	@SuppressWarnings("serial")
	public UserRatingMatrixCache() {
		this.cache = new LinkedHashMap<Integer, UserRating[]>(CACHE_MAX_SIZE,
				0.75f, true) {
			protected boolean removeEldestEntry(
					Map.Entry<Integer, UserRating[]> eldest) {
				return size() > CACHE_MAX_SIZE;
			}
		};
	}

	public boolean containsKey(int userId) {
		return this.cache.containsKey(userId);
	}

	public UserRating[] get(int userId) {
		return this.cache.get(userId);
	}

	public void put(int userId, UserRating[] ratings) {
		this.cache.put(userId, ratings);

	}
}
